package com.shopping.control;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shopping.dao.impl.BizDaoImpl;
import com.shopping.entity.TbAffiche;
import com.shopping.service.impl.BizServiceImpl;

/**
 * Servlet implementation class XiugaiServlet
 */
public class XiugaiServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public XiugaiServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see Servlet#init(ServletConfig)
     */
    @Override
    public void init(ServletConfig config) throws ServletException {
        // TODO Auto-generated method stub
    }

    /**
     * @see Servlet#destroy()
     */
    @Override
    public void destroy() {
        // TODO Auto-generated method stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
            IOException {

        BizDaoImpl bdi = new BizDaoImpl();
        BizServiceImpl bsi = new BizServiceImpl();
        bsi.setBizdao(bdi);

        TbAffiche tba = new TbAffiche();
        tba.setId(Integer.parseInt(request.getParameter("id")));
        // System.out.println(request.getParameter("id"));

        tba.setName(request.getParameter("name"));
        tba.setContent(request.getParameter("content"));
        Date date = new Date();
        tba.setIssueTime(date);
        /*
         * SimpleDateFormat sdf = new SimpleDateFormat("YYYY-mm-dd hh:mm:ss");
         * tba.setIssueTime(java.sql.Date.valueOf(sdf.format(date)));
         */

        int flag = bsi.updateAffiche(tba);
        if (flag > 0) {
            // request.getRequestDispatcher("affiche").forward(request,
            // response);
            response.sendRedirect("affiche");
        }
    }

}
